package com.zbkj.crmeb.enums.logistics;

import com.baomidou.mybatisplus.core.enums.IEnum;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;

import java.util.Objects;

/**
 * 物流方式
 *
 * @author lvmd
 * @date 2021-01-06
 */
public enum LogisticsTypeEnum implements IEnum<Integer> {
    /**
     * 默认自行发货
     */
    DEFAULT(0, "自行发货"),
    /**
     * 平台物流（物流部门未操作）
     */
    PLATFORM(1, "平台物流"),
    /**
     * 海外直邮
     */
    DIRECT(2, "海外直邮"),
    /**
     * 跨境转运
     */
    TRANSFER(3, "跨境转运"),

    ;

    private final Integer code;
    private final String msg;

    LogisticsTypeEnum(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public Integer getCode() {
        return code;
    }

    public String getMsg() {
        return msg;
    }

    @JsonCreator
    public static LogisticsTypeEnum valueOf(Integer code) {
        for (LogisticsTypeEnum value : values()) {
            if (code.equals(value.getCode())) {
                return value;
            }
        }
        return LogisticsTypeEnum.DEFAULT;
    }

    @Override
    @JsonValue
    public Integer getValue() {
        return code;
    }

    /**
     * 根据code得到枚举的Value
     *
     * @param code
     * @return
     */
    public static String getEnumValue(Integer code) {
        if (Objects.isNull(code)){
            return LogisticsTypeEnum.DEFAULT.getMsg();
        }
        LogisticsTypeEnum[] logisticsTypeEnums = LogisticsTypeEnum.values();
        for (LogisticsTypeEnum logisticsTypeEnum : logisticsTypeEnums) {
            if (code.equals(logisticsTypeEnum.getCode())) {
                return logisticsTypeEnum.getMsg();
            }
        }
        return null;
    }

}

